package com.pudu.mydemo.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pudutech.pdrobot.R;

import java.util.Timer;
import java.util.TimerTask;


public class WifiPswDialog extends Dialog{
	private ImageView cancelButton;
	private ImageView okButton;
	private EditText pswEdit;
	private LinearLayout wifi_dialog;
	private OnCustomDialogListener customDialogListener;
	private TextView wifi_name;
	private Timer timer;
	private int width,height;
	private View customView;
	private String wifiname;
	public WifiPswDialog(Context context,String wifiname,OnCustomDialogListener customListener) {
		//OnCancelListener cancelListener) {
		super(context);
		// TODO Auto-generated constructor stub
		customDialogListener = customListener;
		this.wifiname = wifiname;
		customView = LayoutInflater.from(context).inflate(R.layout.wifi_login_dialog, null);
	}
	//定义dialog的回调事件
	public interface OnCustomDialogListener{
		void back(String str);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.wifi_login_dialog);
		//setTitle("请输入密码");
		wifi_dialog = (LinearLayout)findViewById(R.id.login_dialog);
		pswEdit = (EditText)findViewById(R.id.password);
		cancelButton = (ImageView)findViewById(R.id.cancel);
		okButton = (ImageView)findViewById(R.id.ok);
		cancelButton.setOnClickListener(buttonDialogListener);
		wifi_name = (TextView)findViewById(R.id.wifi_name);
		okButton.setOnClickListener(buttonDialogListener);

		wifi_name.setText(wifiname);

	}

	private View.OnClickListener buttonDialogListener = new View.OnClickListener() {

		@Override
		public void onClick(View view) {
			// TODO Auto-generated method stub
			if(view.getId() == R.id.wifiDialogCancel){
				pswEdit = null;
				customDialogListener.back(null);
				cancel();//自动调用dismiss();
			}
			else{
				customDialogListener.back(pswEdit.getText().toString());
				dismiss();
			}
		}
	};

	public  void setDialogWindowAttr(Context ctx){
		Window window = this.getWindow();
		WindowManager.LayoutParams lp = window.getAttributes();
		lp.gravity = Gravity.CENTER;
		lp.width = wifi_dialog.getWidth();//宽高可设置具体大小
		lp.height = wifi_dialog.getHeight();
		lp.width = 400;//宽高可设置具体大小
		lp.height = 350;
		this.getWindow().setAttributes(lp);
	}

	public View getCustomView() {
		return customView;
	}
}
